package org.rcgwt.client.ui.validator.impl;

import org.rcgwt.client.ui.validator.ICharacterSets;
import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.IFilter;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.IValidatorElement;

/**
 * Filter which filters number characters (like digits, plus, minus, and dot
 * character)
 * 
 * @author Elian ORIOU
 */

public class NumberFilter implements IFilter, ISingleton {

	private static final NumberFilter INSTANCE = new NumberFilter();

	private static final String MY_PATTERN = ICharacterSets.NUM_SET;

	protected NumberFilter() {

	}

	@Override
	public boolean filter(IClientValidatorContext context, char c) {
		if (MY_PATTERN.indexOf(c) != -1 || c == '+' || c == '-' || c == '.') {
			return true;
		}
		return false;
	}

	public static IValidatorElement getInstance() {
		return INSTANCE;
	}
}
